﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Base4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // 显示CheckedListBox选中项
        private void btnShow_Click(object sender, EventArgs e)
        {
            foreach(string iterm in this.clbIterm.CheckedItems)
            {
                MessageBox.Show(iterm);
            }
        }

        // 动态添加CheckedListBox中的选中项到ListBox
        private void btnAdd_Click(object sender, EventArgs e)
        {
            List<string> sl = new List<string>();
            foreach (string iterm in this.clbIterm.CheckedItems)
            {
                sl.Add(iterm);
            }

            this.lbIterm.Items.Clear();
            this.lbIterm.Items.AddRange(sl.ToArray());
        }

        private void btnGet_Click(object sender, EventArgs e)
        {
            foreach(string iterm in this.lbIterm.SelectedItems)
            {
                MessageBox.Show(iterm);
            }
        }

        private void btnShowNumber_Click(object sender, EventArgs e)
        {
            string text = this.mtbNumber.Text;
            MessageBox.Show(text);

            string[] sa = text.Split('-');
            text = String.Join("",sa);  // 将字符数组合并为一个字符串，并以前面给的“”字符串进行串联

            MessageBox.Show(text);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            int max = 100;
            int min = 0;
            int seed = Guid.NewGuid().GetHashCode();
            Random random = new Random(seed);
            this.txtB.Text = random.Next(min, max).ToString();       // Next，包含下限，不包含上限。
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            this.timer1.Start();
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            this.timer1.Stop();
        }
    }
}
